/*NKWH81mr+pdPRcsBySGRrR7eV8VigfTQdCrim5nAR7wYMCADmdFIwVTUPzLV+XjP*/
/*
 * @Author: xiahui 
 * @PageInfo: 表头过滤
 * @Date: 2019-02-14 14:44:08 
 * @Last Modified by: zhr
 * @Last Modified time: 2021-09-08 22:39:00
 */
import { AREA, FIELDS } from '../../constance';
import { setRefMainOrgVIDPermissonByItem } from '../../../pub/utils/referUtil';
import { rateTypeSellFilter } from '../../../../../scmpub/scmpub/pub/tool/currencyRateUtil';

function headReferFilter(props, meta, moduleId) {
	meta[moduleId].items.map((item) => {
		if (item.attrcode == FIELDS.pk_org_v) {
			// 主组织
			setRefMainOrgVIDPermissonByItem(item);
		} else if (item.attrcode == FIELDS.ctrantypeid) {
			// 交易类型
			item.queryCondition = () => {
				let bodysize = props.cardTable.getNumberOfRows(AREA.cardTableId);
				let vsrctype = null;
				let cectypecode = null;
				let pk_ct_price = null;
				if (bodysize > 0) {
					vsrctype = props.cardTable.getValByKeyAndIndex(AREA.cardTableId, 0, FIELDS.vsrctype).value;
					cectypecode = props.cardTable.getValByKeyAndIndex(AREA.cardTableId, 0, FIELDS.cectypecode).value;
					pk_ct_price = props.cardTable.getValByKeyAndIndex(AREA.cardTableId, 0, FIELDS.pk_ct_price).value;
				}
				return {
					VSRCTYPE: vsrctype,
					CECTYPECODE: cectypecode,
					PK_CT_PRICE: pk_ct_price,
					GridRefActionExt: 'nccloud.web.ct.purdaily.ref.Z2BillTypeRefSql'
				};
			};
		} else if (item.attrcode == FIELDS.personnelid) {
			// 人员
			item.isShowUnit = false;
			item.queryCondition = () => {
				let pk_org = (props.form.getFormItemsValue(AREA.cardFormId, FIELDS.pk_org) || {}).value;
				let pk_dept = (props.form.getFormItemsValue(AREA.cardFormId, FIELDS.depid) || {}).value;
				return {
					pk_org: pk_org,
					pk_dept: pk_dept,
					busifuncode: 'pu'
				};
			};
		} else if (item.attrcode == FIELDS.deliaddr) {
			// 交货地点
			item.queryCondition = () => {
				let pk_group = props.form.getFormItemsValue(moduleId, FIELDS.pk_group).value;
				return {
					pk_group: pk_group
				};
			};
		} else if (item.attrcode == FIELDS.depid_v) {
			// 部门
			item.queryCondition = () => {
				let pk_org = props.form.getFormItemsValue(moduleId, FIELDS.pk_org).value;
				return {
					pk_org: pk_org,
					busifuncode: 'pu'
				};
			};
		} else if (item.attrcode == FIELDS.cprojectid) {
			// 项目
			item.queryCondition = () => {
				let pk_org = props.form.getFormItemsValue(moduleId, FIELDS.pk_org).value;
				return {
					pk_org: pk_org,
					busifuncode: 'pu'
				};
			};
		} else if (item.attrcode == FIELDS.cvendorid || item.attrcode == FIELDS.cvendorvid) {
			// 供应商
			item.queryCondition = () => {
				let pk_org = props.form.getFormItemsValue(moduleId, FIELDS.pk_org).value;
				return {
					pk_org: pk_org
				};
			};
		} else if (item.attrcode == FIELDS.pk_payterm) {
			// 付款协议
			item.queryCondition = () => {
				let pk_org = props.form.getFormItemsValue(moduleId, FIELDS.pk_org).value;
				return {
					pk_org: pk_org
				};
			};
		} else if (item.attrcode.indexOf('vdef') == 0 && item.itemtype == 'refer') {
			// 自定义
			item.queryCondition = () => {
				let pk_org = props.form.getFormItemsValue(moduleId, FIELDS.pk_org).value;
				return { pk_org: pk_org };
			};
		} else if (item.attrcode == FIELDS.cratetype) {
			//汇率类型
			item.queryCondition = () => {
				return rateTypeSellFilter();
			};
		}
	});
}

export { headReferFilter };

/*NKWH81mr+pdPRcsBySGRrR7eV8VigfTQdCrim5nAR7wYMCADmdFIwVTUPzLV+XjP*/